<!DOCTYPE html>
<html lang="zh-CN">
<head><meta charset="UTF-8"><title><?= isset($package) ? '编辑套餐' : '添加套餐' ?></title>
<link rel="stylesheet" href="/layui/css/layui.css"><script src="/static/js/jquery.min.js"></script><script src="/layui/layui.js"></script>
<style>body{background:#f5f5f5;padding:20px;}</style></head>
<body>
<div class="layui-card"><div class="layui-card-header"><?= isset($package) ? '编辑套餐' : '添加套餐' ?></div><div class="layui-card-body">
<form class="layui-form" lay-filter="pkgForm">
<?= $csrfField ?? '' ?><?php if(isset($package)): ?><input type="hidden" name="id" value="<?= $package['id'] ?>"><?php endif; ?>
<div class="layui-form-item"><label class="layui-form-label">套餐名称</label><div class="layui-input-block" ><input type="text" name="name" value="<?= htmlspecialchars($package['name'] ?? '') ?>" lay-verify="required" class="layui-input"></div></div>
<div class="layui-form-item"><label class="layui-form-label">关联通道</label><div class="layui-input-block" ><select name="channel_id" lay-verify="required"><option value="">请选择</option><?php foreach($channels as $ch): ?><option value="<?= $ch['id'] ?>" <?= isset($package) && $package['channel_id']==$ch['id']?'selected':'' ?>><?= $ch['name'] ?> (<?= $ch['type_name']?:$ch['type'] ?>)</option><?php endforeach; ?></select></div></div>
<div class="layui-form-item"><label class="layui-form-label">调用次数</label><div class="layui-input-block" ><input type="number" name="call_limit" value="<?= $package['call_limit'] ?? 100 ?>" lay-verify="required" class="layui-input"></div></div>
<div class="layui-form-item"><label class="layui-form-label">价格(元)</label><div class="layui-input-block" ><input type="number" step="0.01" name="price" value="<?= $package['price'] ?? '0.00' ?>" lay-verify="required" class="layui-input"></div></div>
<div class="layui-form-item"><label class="layui-form-label">有效期(天)</label><div class="layui-input-block" ><input type="number" name="valid_days" value="<?= $package['valid_days'] ?? 30 ?>" lay-verify="required" class="layui-input"></div></div>
<div class="layui-form-item"><label class="layui-form-label">排序</label><div class="layui-input-block" ><input type="number" name="sort" value="<?= $package['sort'] ?? 100 ?>" class="layui-input"></div></div>
<div class="layui-form-item"><label class="layui-form-label">状态</label><div class="layui-input-block"><input type="radio" name="status" value="1" title="上架" <?= (!isset($package)||$package['status']==1)?'checked':'' ?>> <input type="radio" name="status" value="0" title="下架" <?= (isset($package)&&$package['status']==0)?'checked':'' ?>></div></div>
<div class="layui-form-item"><label class="layui-form-label">描述</label><div class="layui-input-block" ><textarea name="description" class="layui-textarea"><?= htmlspecialchars($package['description'] ?? '') ?></textarea></div></div>
<div class="layui-form-item"><div class="layui-input-block"><button class="layui-btn" lay-submit lay-filter="savePkg"><?= isset($package)?'保存修改':'添加套餐' ?></button> <a href="/admin/package/index" class="layui-btn layui-btn-primary">返回</a></div></div>
</form></div></div>
<script>
layui.use('form',function(){var f=layui.form;f.on('submit(savePkg)',function(d){var url='<?= isset($package)?"/admin/package/edit":"/admin/package/add"?>';$.post(url,d.field,function(r){layer.msg(r.msg,{icon:r.code===0?1:2});if(r.code===0) setTimeout(function(){location.href='/admin/package/index';},1000);});return false;});});
</script></body></html>